# $Id: PKGBUILD 175849 2013-01-22 18:43:29Z daniel $
# Maintainer: Daniel Isenmann <daniel@archlinux.org>
# Contributor: Rashif "Don Ray" Rahman <rayrashif@gmail.com>

pkgbase=wicd
pkgname=('wicd' 'wicd-gtk')
pkgver=1.7.2.4
pkgrel=6
arch=(any)
url="http://wicd.sourceforge.net/"
license=('GPL2')
conflicts=('wicd-svn')
install=wicd.install
source=(http://launchpad.net/wicd/1.7/$pkgver/+download/wicd-$pkgver.tar.gz             wicd-daemon
        wicd.desktop
        dbus_string_fix.patch
	http://bazaar.launchpad.net/~wicd-devel/wicd/experimental/diff/831
	http://bazaar.launchpad.net/~wicd-devel/wicd/experimental/diff/835)
makedepends=('python2' 'python2-babel' 'python2-distribute' 'gettext')
options=('emptydirs')
md5sums=('c2435ddfdef0b9898852d72a85a45f0f'
         'f40e5f59998d0829707a7c9976afa8f8'
         '326df163a5732d38741371baa4fce9e5'
         '744b3c12fe901ed435351e884dc8cb1d'
         '0d2355bc2eb7234a537f42f1773edfe0'
         '1630d7fe8f09911302d33b26286ff9b8')

build() {
  cd "$srcdir/$pkgbase-$pkgver"

  find . -type f -exec sed -i 's@#!/usr.*python@#!/usr/bin/python2@' {} \;
  export PYTHON=python2
  
  patch -p0 < "$srcdir/dbus_string_fix.patch"
  
  # Fix problem with new urwid FS#33378 LP#1075399
  patch -Np0 -i "$srcdir/831"
  patch -Np0 -i "$srcdir/835"


  python2 setup.py configure --no-install-init \
	                     --resume=/usr/share/wicd/scripts/ \
                             --suspend=/usr/share/wicd/scripts/ \
                             --verbose \
                             --python=/usr/bin/python2 \
			     --lib=/usr/lib \
			     --systemd=/usr/lib/systemd/system
  
  #HACK for https://bugs.launchpad.net/wicd/+bug/928589
  mkdir -p translations/ast/LC_MESSAGES
  msgfmt po/ast.po -o translations/ast/LC_MESSAGES/wicd.mo
}

package_wicd() {
  pkgdesc="Wired and wireless network manager for Linux"
  depends=('python2' 'python2-dbus' 'dhcpcd' 'wpa_supplicant' 'wireless_tools'
           'inetutils' 'net-tools' 'ethtool' 'shared-mime-info' 'python2-urwid' 'python2-gobject2' 'dbus-glib' 'rfkill')
  optdepends=('wicd-gtk: needed if you want the GTK interface')
  backup=('etc/wicd/encryption/templates/active')
  install=wicd.install  

  cd "$srcdir/$pkgbase-$pkgver"
  python2 setup.py install --optimize=1 --root="$pkgdir"

  # Add custom rc.d script
  install -Dm755 "$srcdir/wicd-daemon" "$pkgdir/etc/rc.d/wicd"

  cd build/lib/wicd
  for i in *.py; do
    install -Dm 755 $i "$pkgdir/usr/lib/wicd/$i"
  done
  
  rm -rf "$pkgdir"/usr/share/autostart

  #deleting the GTK stuff
  rm -rf "$pkgdir"/etc/xdg
  rm -f "$pkgdir"/usr/bin/{wicd-client,wicd-gtk}
  rm -rf "$pkgdir"/usr/share/{applications,icons,pixmaps}
  rm -rf "$pkgdir"/usr/share/wicd/gtk  
}

package_wicd-gtk() {
  pkgdesc="Wired and wireless network manager for Linux - GTK client"
  depends=('wicd' 'pygtk')
  optdepends=('gksu: needed to access some preferences in gtk interface'
              'notification-daemon: needed if you want notifications'
              'python2-notify:	needed if you want notifications'
              'hicolor-icon-theme')

  cd "$srcdir/$pkgbase-$pkgver"
  python2 setup.py install --optimize=1 --root="$pkgdir"

  install -Dm644 "$srcdir/wicd.desktop" "$pkgdir/usr/share/applications/wicd.desktop"

  cd build/lib/wicd
  for i in *.py; do
    install -Dm 755 $i "$pkgdir"/usr/lib/wicd/$i
  done
  
  #deleting the core dirs which exists in wicd
  rm -rf "$pkgdir"/etc/{wicd,dbus-1,rc.d,logrotate.d}
  rm -rf "$pkgdir"/usr/{lib,sbin}
  rm -rf "$pkgdir"/usr/share/{man,doc,locale,wicd/curses,wicd/daemon,wicd/backends,wicd/scripts,wicd/cli}
  rm -rf "$pkgdir"/var
  rm -f "$pkgdir"/usr/bin/{wicd-curses,wicd-cli}

  rm -rf "$pkgdir"/usr/share/autostart
  rm -rf "$pkgdir"/lib/
  rm -rf "$pkgdir"/usr/share/dbus-1
}
